//
//  ChangeNameVC.m
//  hnGovernment
//
//  Created by 安仔 on 17/3/6.
//  Copyright © 2017年 安仔. All rights reserved.
//

#import "ChangeNameVC.h"
#import "ChangeView.h"
#import "FinishChangeNameVC.h"
#import "DDcacheManager.h"
#import "DDbaseNetWork+Login.h"
#import "DDcacheManager.h"
#import "DDHudHelper.h"
@interface ChangeNameVC ()<ChangeViewDelegate>
@property (nonatomic, strong) ChangeView *changeView;

@end

@implementation ChangeNameVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = NSLocalString(@"修改昵称");
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.changeView = [[ChangeView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight - 128 * m6Scale)];
    self.changeView.signImg.hidden = YES;
    self.changeView.signLab.hidden = NO;

    NSString *title = [NSString stringWithFormat:@"当前昵称：%@",[cacheManager getUserModel].displayName];
    NSString *string = NSLocalString(title);
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:string];
    [str addAttribute:NSForegroundColorAttributeName value:RGB(103, 103, 103) range:NSMakeRange(0,5)];
    [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:32 * m6Scale] range:NSMakeRange(0,5)];
    self.changeView.signLab.attributedText = str;
    
    self.changeView.phoneTF.placeholder = NSLocalString(@"请输入新昵称");
    self.changeView.delegate = self;
    self.changeView.isChangeName = YES;
    [self.view addSubview:self.changeView];
   
}

- (void)clickNextBtn {
    
    WEAKSELF
    [DDNetWorkManager saveUserInfoWithToken:[cacheManager userToken] displayName:self.changeView.phoneTF.text passport:nil military:nil receiverName:nil mobile:nil province:nil city:nil district:nil street:nil details:nil controller:self success:^(id result, DDcacheType cacheType, DDresultType resultType) {
        [DDHudHelper showHudWithResult:result resultSuccess:^{
            ZWUserModel *model = [cacheManager getUserModel];
            model.displayName = weakSelf.changeView.phoneTF.text;
            [cacheManager cacheUserInfoWithModel:model];
            FinishChangeNameVC *vc = [[FinishChangeNameVC alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }];
    } failure:^(NSError *error) {
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
